package dailyExe.hashTable;

import java.util.HashMap;

public class 同构字符串 {
    public static void main(String[] args) {
        isIsomorphic("paper","title");
    }
    public static boolean isIsomorphic(String s, String t) {
        HashMap<Character, Character> map = new HashMap<Character, Character>();
        for (int i = 0; i < s.length(); i++) {
            char charredAtS = s.charAt(i);
            char charredAtT = t.charAt(i);
            if (map.containsKey(charredAtS)) {
                //看看是不是对应
                Character value = map.get(charredAtS);
                if (value != charredAtT) return false;
            }else {
                //放的时候看看 对应值有没有被对应 有的话说明已经被使用
                if(map.containsValue(charredAtT)) return false;
                map.put(charredAtS, charredAtT);
            }
        }
        return true;
    }
}
